<?php

namespace App\Http\Service;
use App\Models\HonestassetProduct as HonestassetProduct;
/**
 * Author: H J
 * Date: 2016/11/17 10:25
 * Description:
 */
class HonestassetPoroductService {

    /*
     * @author wangan
     * @since 20161117
     * @desc 分页查询产品列表
     * @param $pageSize$sVal搜索值
     * */
    public static function getProductListPageinit($pageSize=DEFAULT_PAGESIZE,$where=[],$searchVal=null){
        $productEnity=HonestassetProduct::where($where)
            ->orderBy('sort','DESC')
            ->orderBy('id','DESC');
        if(!empty($searchVal)){
            return $productEnity->where('name','like','%'.$searchVal.'%')
                                ->paginate($pageSize);
        }
        return $productEnity->paginate($pageSize);
    }
    /*
     * @author wangan
     * @since 2016 11 18
     * @desc 获取产品状态列表
     * */
    public static function getProductStatusList(){
        return HonestassetProduct::getStatusList();
    }
    /*
     * @author wangan
     * @since 2016 11 19
     * @desc 获取产品 审核状态列表
     */
    public static function getProductVerifyStatusList(){
        return  HonestassetProduct::getVerifyStatusList();
    }

    public static function createOneProduct($productData){
        if(HonestassetProduct::create($productData)) {
            return true;
        }else{
            return false;
        }
    }
    public static function getOneProduct($productId){
        return HonestassetProduct::find($productId);
    }
    public static function updateOneProduct($productData){
        return HonestassetProduct::find($productData['id'])
                ->update($productData);
    }
    public static function deleteOneProduct($productId){
        $productData=array('isdelete'=>'1');
        return HonestassetProduct::find($productId)
            ->update($productData);
    }
}